package huizhi.exercise;

import cn.hutool.core.util.StrUtil;

import java.io.File;
import java.nio.charset.StandardCharsets;

public class FileExercise {
    public static void main(String[] args) {
        returnFilePath("C:/Users/Administrator/Desktop/后端","sql");
    }

    /**
     * 写一个方法，传入一个路径+关键字，返回包含指定关键字的文件路径
     *
     * 	C:\Users\Administrator\Desktop\tmp    1111
     */
    private static void returnFilePath(String url,String name) {
        File file = new File(url);
        File [] files = file.listFiles();
        for (File file1 : files) {
            if (file1.isDirectory()){
                returnFilePath(file1.getAbsolutePath(),name);
            }
            if (file1.isFile()){
                if (StrUtil.contains(file1.getName(),name)){
                    System.out.println(file1.getAbsoluteFile());
                }
            }
        }
    }
}
